package niumao.minecraft.uhc.commands;

import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class WorldList implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (sender instanceof Player) {
            Player player = (Player) sender;
            if (!player.isOp()) {
                player.sendMessage("Only Op can execute this command!");
                return true;
            }
            if (cmd.getName().equalsIgnoreCase("worldlist")) {
                player.sendMessage(ChatColor.GREEN + "-----" + ChatColor.GOLD + "Loaded World" + ChatColor.GREEN + "-----");
                for (int i = 0; i < Bukkit.getWorlds().size(); i++)
                    player.sendMessage((i + 1) + ": " + ChatColor.GREEN + Bukkit.getWorlds().get(i).getName().toString());
                return true;
            }
        }
        sender.sendMessage(ChatColor.RED + "only Player can executor this command!");
        return true;
    }
}
